package com.example.mallsystem1104.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.mallsystem1104.entity.Good;
import com.example.mallsystem1104.entity.GoodStandard;
import com.example.mallsystem1104.entity.dto.GoodDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;


/**
 * @Author zy
 * @Date 2024/12/10 17:55
 * @packageName:com.example.mallsystem1104.mapper
 * @ClassName:GoodMapper
 */
@Mapper
public interface GoodMapper extends BaseMapper<Good> {
    @Select("select good.*,MIN(gs.price)*discount as price from good left join good_standard as gs on good.id=gs.good_id "+
    "where is_delete=0 and recommend=1 group by good.id order by price ASC")
    List<GoodDTO> findAllGoods();

    @Select("select * from good_standard where good_id=#{id}")
    List<GoodStandard> getStandById(Long id);

    @Select("select discount*MIN(price) from good_standard gs,good where good.id=gs.good_id and good.id=#{id}")
    BigDecimal getMinPrice(Long id);

    void insertGood(Good good);

    void saleGood(Long goodId, int count, BigDecimal totalPrice);

    @Select("select * from `good` where is_delete=0 order by sale_money desc limit 0,#{num}")
    List<Good> getSaleRank(int num);
}
